package com.gitee.ice1938.mvc.base;
/**
 * Ajax返回数据
 * 
 * @author ice1938@qq.com cocklebur-generator  2019-11-28 14:13:15 
 *<a href="https://gitee.com/ice1938">gitee</a><br>
 * <a href="https://github.com/spring256">github</a>
 *
 */
public class AjaxResult {

	private String message;
	private int code = 200; // 200: normal , >=200 : error
	private Object data;

	public AjaxResult() {

	}

	public AjaxResult(Object data) {
		this.data = data;
	}

	public AjaxResult(String message, Object data) {
		this.message = message;
		this.data = data;
	}

	public AjaxResult(String message, int code) {
		this.message = message;
		this.code = code;
	}

	public AjaxResult(int code, String message) {
		this.message = message;
		this.code = code;

	}

	public String getMessage() {
		return message;
	}

	public AjaxResult setMessage(String message) {
		this.message = message;
		return this;
	}

	public Object getData() {
		return data;
	}

	public AjaxResult setData(Object data) {
		this.data = data;
		return this;
	}

	public int getCode() {
		return code;
	}

	public AjaxResult setCode(int code) {
		this.code = code;
		return this;
	}

	public static AjaxResult ok() {
		return new AjaxResult(200, "success");
	}

	public static AjaxResult error() {
		return error(500, "error");
	}

	public static AjaxResult error(String msg) {
		return error(500, msg);
	}

	public static AjaxResult error(int code, String msg) {
		return new AjaxResult(code, msg);
	}
}
